// 事件滚动效果
window.state = '1'; //人员列表选中状态 获取全部人员数据和取消所有人员
window.ARR = []; //已经选择的人员

function tableScroll(tableid, hei, speed, len) {
	clearTimeout(MyMarhq);
	$('#' + tableid).parent().find('.tableid_').remove()
	$('#' + tableid).parent().prepend(
		'<table class="tableid_"><thead>' + $('#' + tableid + ' thead').html() + '</thead></table>'
	).css({
		'position': 'relative',
		'overflow': 'hidden',
		'height': hei + 'px'
	})
	// $(".tableid_").find('th').each(function(i) {
	//     $(this).css('width', $('#' + tableid).find('th:eq(' + i + ')').width());
	// });
	$(".tableid_").css({
		'position': 'absolute',
		'top': 0,
		'left': 0,
		'z-index': 9
	})
	$('#' + tableid).css({
		'position': 'absolute',
		'top': 0,
		'left': 0,
		'z-index': 1
	})

	if ($('#' + tableid).find('tbody tr').length > len) {
		$('#' + tableid).find('tbody').html($('#' + tableid).find('tbody').html() + $('#' + tableid).find('tbody').html());
		$(".tableid_").css('top', 0);
		$('#' + tableid).css('top', 0);
		var tblTop = 0;
		var outerHeight = $('#' + tableid).find('tbody').find("tr").outerHeight();

		function Marqueehq() {
			if (tblTop <= -outerHeight * $('#' + tableid).find('tbody').find("tr").length) {
				tblTop = 0;
			} else {
				tblTop -= 1;
			}
			$('#' + tableid).css('margin-top', tblTop + 'px');
			clearTimeout(MyMarhq);
			MyMarhq = setTimeout(function() {
				Marqueehq()
			}, speed);
		}

		MyMarhq = setTimeout(Marqueehq, speed);
		$('#' + tableid).find('tbody').hover(function() {
			clearTimeout(MyMarhq);
		}, function() {
			clearTimeout(MyMarhq);
			if ($('#' + tableid).find('tbody tr').length > len) {
				MyMarhq = setTimeout(Marqueehq, speed);
			}
		})
	}

}
// 滚动事件列表
function scrollTableData() {
	var scroll_t = [{
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
			liuzhuan: 'lee',
			chuli: 'lee'
		}, {
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
			liuzhuan: 'lee',
			chuli: 'lee'
		}, {
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
			liuzhuan: 'lee',
			chuli: 'lee'
		},
		{
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
		}, {
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
			liuzhuan: 'lee',
			chuli: 'lee'
		},
		{
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
			liuzhuan: 'lee',
			chuli: 'lee'
		}

	]
	for (var j = 0; j < scroll_t.length; j++) {
		$('#scrool-table').append(
			"<tr>" +
			"<td>" + scroll_t[j].title + "</td>" +
			"<td>" + scroll_t[j].index + "</td>" +
			"<td>" + scroll_t[j].name + "</td>" +
			"<td>" + scroll_t[j].liuzhuan + "</td>" +
			"<td>" + scroll_t[j].chuli + "</td>" +
			"<td onClick='dispose(\"" + scroll_t[j].title + "\");'>" + '处置' + "</td>" +
			"</tr>");
	}
	$("#scrool-table tr :nth-child(6)").addClass('selectTable');
}
//人员全选 反选  以及赋值
function selectAll() {
	var checkBoxObject = document.getElementsByName("cb");
	if (window.state == '1') {
		for (var i = 0; i < checkBoxObject.length; i++) {
			// 设置每一个checkbox的状态为选中 checked
			checkBoxObject[i].checked = true;
			window.state = '2';
		}
		$("#people_list tr").each(function() {
			var count = $(this).children("td:eq(1)").text();
			var name = $(this).children("td:eq(2)").text();
			window.ARR.push({
				name: name,
				count: count
			})
		})
		rightSet()

	} else {
		for (var i = 0; i < checkBoxObject.length; i++) {
			checkBoxObject[i].checked = false;
			window.state = '1'
		}
		window.ARR = []
		$("#people_name div").remove();
	}


}
// 遍历已选择的人员dom
function rightSet() {
	$("#people_name div").remove();
	for (var l = 0; l < window.ARR.length; l++) {
		$("#people_name").append(
			"<div class='p_name_c'>" + "<p class='p_name'>" + window.ARR[l].name + "</p>" +
			"<img class='p_name_img' src=" + './img/x.png' + " onClick='cancelName(\"" + l +','+ window.ARR[l].name + "\");'>"

			+
			"</div>"

		)
	}
}
//已选择的人员删除（节点）
//单选 赋值
function danxuan(v) {
	var v_a = v.split(',')
	for (var b = 0; b < window.ARR.length; b++) {
		if (window.ARR[b].count==v_a[0]) { 
			window.ARR.splice(b,1);
            rightSet()
			return false;
		}

	}
	window.ARR.push({
		count: v_a[0],
		name: v_a[1]
	})
	rightSet()
}
//已选人员标签删除
function cancelName(v) {
	var v_a1 = v.split(',')
	$("#people_list tr").each(function() {
		 var name = $(this).children("td:eq(2)").text();
		if(v_a1[1]==name){
			var index=$(this).index()+1;
			var checkBoxObject = document.getElementsByName("cb");
			checkBoxObject[index].checked=false;
		}
	})
	for (var i = window.ARR.length; i >= 0; i--) {
		if (v_a1[0] == i) {
			window.ARR.splice(i, 1)
			console.log(window.ARR)
		}
	}
	rightSet()
}
// 人员列表
function peopleListTable() {
	var list = [{
			count: 'zhangxiao1',
			name: '张晓1',
			org: '北村东区社区',
			position: '网格长',
			phone: '13398989898'
		},
		{
			count: 'zhangxiao2',
			name: '张晓2',
			org: '北村东区社区',
			position: '网格长',
			phone: '13398989898'
		},
		{
			count: 'zhangxiao3',
			name: '张晓3',
			org: '北村东区社区',
			position: '网格长',
			phone: '13398989898'
		},
		{
			count: 'zhangxiao',
			name: '张晓4',
			org: '北村东区社区',
			position: '网格长',
			phone: '13398989898'
		},
		{
				count: 'zhangxiao1',
				name: '张晓1',
				org: '北村东区社区',
				position: '网格长',
				phone: '13398989898'
			},
			{
				count: 'zhangxiao2',
				name: '张晓2',
				org: '北村东区社区',
				position: '网格长',
				phone: '13398989898'
			},
			{
				count: 'zhangxiao3',
			
				name: '张晓3',
				org: '北村东区社区',
				position: '网格长',
				phone: '13398989898'
			},
			{
				count: 'zhangxiao',
				name: '张晓4',
				org: '北村东区社区',
				position: '网格长',
				phone: '13398989898'
			},
			{
					count: 'zhangxiao1',
					name: '张晓1',
					org: '北村东区社区',
					position: '网格长',
					phone: '13398989898'
				},
				{
					count: 'zhangxiao2',
					name: '张晓2',
					org: '北村东区社区',
					position: '网格长',
					phone: '13398989898'
				},
				{
					count: 'zhangxiao3',
					name: '张晓3',
					org: '北村东区社区',
					position: '网格长',
					phone: '13398989898'
				},
				{
					count: 'zhangxiao',
					name: '张晓4',
					org: '北村东区社区',
					position: '网格长',
					phone: '13398989898'
				},
				{
						count: 'zhangxiao1',
						name: '张晓1',
						org: '北村东区社区',
						position: '网格长',
						phone: '13398989898'
					},
					{
						count: 'zhangxiao2',
						name: '张晓2',
						org: '北村东区社区',
						position: '网格长',
						phone: '13398989898'
					},
					{
						count: 'zhangxiao3',
						name: '张晓3',
						org: '北村东区社区',
						position: '网格长',
						phone: '13398989898'
					},
					{
						count: 'zhangxiao',
						name: '张晓4',
						org: '北村东区社区',
						position: '网格长',
						phone: '13398989898'
					},
					{
							count: 'zhangxiao1',
							name: '张晓1',
							org: '北村东区社区',
							position: '网格长',
							phone: '13398989898'
						},
						{
							count: 'zhangxiao2',
							name: '张晓2',
							org: '北村东区社区',
							position: '网格长',
							phone: '13398989898'
						},
						{
							count: 'zhangxiao3',
							name: '张晓3',
							org: '北村东区社区',
							position: '网格长',
							phone: '13398989898'
						},
						{
							count: 'zhangxiao',
							name: '张晓4',
							org: '北村东区社区',
							position: '网格长',
							phone: '13398989898'
						},
	]
	for (var s = 0; s < list.length; s++) {
		$('#people_list').append(
			"<tr>" +
			"<td>" + "<input type='checkbox' name='cb' onClick='danxuan(\"" + list[s].count + ',' + list[s].name + "\");'>" +
			"</td>" +
			"<td>" + list[s].count + "</td>" +
			"<td>" + list[s].name + "</td>" +
			"<td>" + list[s].org + "</td>" +
			"<td>" + list[s].position + "</td>" +
			"<td>" + list[s].phone + "</td>" +
			"</tr>");
	}
}
//待办事件列表
function tableDataing() {
	var scroll_t1 = [{
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
			liuzhuan: 'lee',
			chuli: 'lee'
		}, {
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
			liuzhuan: 'lee',
			chuli: 'lee'
		}, {
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
			liuzhuan: 'lee',
			chuli: 'lee'
		},
		{
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
			liuzhuan: 'lee',
			chuli: 'lee'
		}, {
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
			liuzhuan: 'lee',
			chuli: 'lee'
		}, {
			title: '垃圾桶翻了',
			index: '待处理',
			name: '2020-12-01 18:00:00',
			liuzhuan: 'lee',
			chuli: 'lee'
		},
	]
	for (var k = 0; k < scroll_t1.length; k++) {
		$('#scrool-table1').append(
			"<tr>" +
			"<td>" + scroll_t1[k].title + "</td>" +
			"<td>" + scroll_t1[k].index + "</td>" +
			"<td>" + scroll_t1[k].name + "</td>" +
			"<td>" + scroll_t1[k].liuzhuan + "</td>" +
			"<td>" + scroll_t1[k].chuli + "</td>" +
			"<td onClick='setEvent(\"" + scroll_t1[k].title + "\");'>" + '查看' + "</td>" +
			"</tr>");
	}
	$("#scrool-table1 tr :nth-child(6)").addClass('selectTable');
}
//查看事件处置流程弹框
function setEvent(title) {
	$("#myModal").show()
	var h = $("#modal_v").height() - 80;
	$('#modal_l').css({
		'height': h
	})
	$("#modal_v").css({
		'height': '80%'
	})
}

function dispose(title) {
	$("#myModal1").show()

}

//人员列表
function showPeople() {
	$("#myModal2").show()
	peopleListTable()
}

function cancelPeople() {
	$("#myModal2").hide()
}
// 事件流转信息 详情
function eventLiuzhuan() {
	var eventListDtails = [{
			time: '2020-12-12 12:00:00',
			name: '石磊 网格员',
			remark: '需要街道协调处理',
			name1: '石磊 网格员',
			remark1: '33号楼南侧'
		},
		{
			time: '2020-12-12 12:00:00',
			name: '石磊 网格员',
			remark: '需要街道协调处理',
			name1: '石磊 网格员',
			remark1: '33号楼南侧'
		},
		{
			time: '2020-12-12 12:00:00',
			name: '石磊 网格员',
			remark: '需要街道协调处理',
			name1: '石磊 网格员',
			remark1: '33号楼南侧'
		}
	]
	for (var s = 0; s < eventListDtails.length; s++) {
		$("#e_v").append(
			"<div class='event-next'>" +
			"<div></div>" +
			"<div class='event-detail'>" +
			"<span>" + eventListDtails[s].time + "</span>" +
			"<div class='inline'>" +
			"<span>" + '流转人:' + eventListDtails[s].name + "</span>" +
			"<span class='chuzhi'>" + '处置' + "</span>" +
			"</div>" +
			"<span>" + '流转意见:' + eventListDtails[s].remark + "</span>" +
			"<span>" + '处理人:' + eventListDtails[s].name1 + "</span>" +
			"<span>" + '处理意见:' + eventListDtails[s].remark1 + "</span>" +

			"</div>" +
			"<div class='event_img'>" +
			"<img src='./img/fanhui.png'>" +
			"</div>" +
			"</div>"
		)
	}

}
//弹框取消
function cancelLiuzhuan() {
	$("#myModal1").hide()
}

function cancelLiuzhuan1() {
	$("#myModal").hide()
}
//流转  处置照片
function btnUploadFile(e) {
	var file = document.getElementById("uploadLocalPic");
	var isIE = navigator.userAgent.match(/MSIE/) != null;
	if (isIE) { //ie9 上传图片
		var url = "test.do";
		$.ajaxFileUpload({
			type: "POST",
			url: url, //路径
			//                  data:dataParam,  //参数
			secureuri: false, //是否启用安全提交，默认为false
			fileElementId: 'uploadLocalPic', //文件选择框的id属性
			dataType: 'json', //服务器返回的格式
			async: false,
			success: function(data) {
				var isSuccess = data.success; //上传成功回显图片 #showIMG.src
				if (!isSuccess) {
					top.artDialog.alert('上传图片失败');
					return;
				}
			},

		});
	} else { //ie11,谷歌  上传图片
		var reader = new FileReader();
		reader.readAsDataURL(file.files[0]);
		//监听文件读取结束后事件
		reader.onloadend = function(e) {
			var img = e.target.result;
			var url = "test.do";
			var param = {
				content: img
			};
			$.ajax({
				url: url,
				async: false,
				data: param,
				type: "Post",
				dataType: "json",
				success: function(data) {
					var isSuccess = data.success;
					if (!isSuccess) {
						top.artDialog.alert('上传图片失败');
						return;
					}
				},
			})
		}
	}
}
//流转时间选择------
$(function() {
	$('#mydatepicker2').dcalendarpicker({
		format: 'yyyy-mm-dd'
	});
	console.log($("#mydatepicker2").value)

})

function selectSet() {
	var id = $("#selectState").val();
	if (id == 2) {
		$("#liuzhuanren").show();
		$("#setTime").show()
	} else {
		$("#liuzhuanren").hide();
		$("#setTime").hide()
	}
}
